from sqlalchemy import Column, Integer, String, Boolean, DateTime, Enum
from sqlalchemy.sql import func
from .base import Base

class Contract(Base):
    """合约信息表 - 精简版"""
    __tablename__ = "contracts"

    # 使用字符串作为枚举类型，避免循环导入
    id = Column(Integer, primary_key=True, autoincrement=True, comment="ID")
    exchange = Column(String(20), nullable=False, comment="交易所类型")
    symbol = Column(String(50), nullable=False, comment="合约符号")
    mark_price_round = Column(String(20), nullable=True, comment="标记价格精度")
    quanto_multiplier = Column(String(20), nullable=True, comment="合约乘数")
    is_active = Column(Boolean, default=True, comment="是否活跃")
    
    # 时间信息
    created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
    updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")

    def __repr__(self):
        return f"<Contract(exchange={self.exchange}, symbol={self.symbol})>" 
    


    def get_quanto_multiplier(self):
        """获取合约乘数"""
        return self.quanto_multiplier
    